/**
 * Page.java
 * Version 1.0.0
 * Created on 2018年7月16日
 *
 */
package com.yincheng.oes.business.util;

/**
 * @author yangsy
 * @version 1.0.0
 * @since
 * 创建时间：2018年7月16日
 * 功能描述：分页参数实体
 * 邮箱地址：446948434@qq.com
 */
public class Page {
    private static Integer DEFAULT_CURRENT = 1;

    private static Integer DEFAULT_SIZE = 10;

    /**
     * 当前页码
     */
    private Integer currentPage;

    /**
     * 每页大小
     */
    private Integer pageSize;

    /**
     * 开始行号
     */
    private Integer startRow;

    /**
     * 结束行号
     */
    private Integer endRow;

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getStartRow() {
        return startRow;
    }

    public Integer getEndRow() {
        return endRow;
    }

    public void setTotal(Integer total) {

        Integer totalrows = (total == null || total < 0) ? 0 : total;
        Integer pagesize = (this.pageSize == null || this.pageSize < 1) ? DEFAULT_SIZE : this.pageSize;
        Integer pagecount = totalrows / pagesize;
        Integer totalpage = (totalrows - pagecount * pagesize) > 0 ? (pagecount + 1) : pagecount;
        Integer currentpage = this.currentPage == null ? DEFAULT_CURRENT
                : (this.currentPage < 1 ? 1 : (this.currentPage > totalpage ? totalpage : currentPage));
        this.startRow = pagesize * (currentpage - 1) < 0 ? 0 : pagesize * (currentpage - 1);
        this.endRow = pagesize * currentpage < 1 ? DEFAULT_SIZE : pagesize * currentpage;
    }

    @Override
    public String toString() {
        return "Page{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", startRow=" + startRow +
                ", endRow=" + endRow +
                '}';
    }
}
